/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    //用于比较A左右子树
    bool isson(TreeNode* A,TreeNode* B){
        if(B==nullptr)
            return true;
        if(A==nullptr)
            return false;
        //对比
        if(A->val!=B->val)
            return false;
        return isson(A->left,B->left)&&isson(A->right,B->right);
    }
    bool isSubStructure(TreeNode* A, TreeNode* B) {
        if(B==nullptr){
            return false;
        }
        if(A==nullptr){
            return false;
        }
        //val相同，开始对比,用result进行记录
        int result=false;
        if(A->val==B->val){
            result=isson(A,B);
        }
        //没有找到，递归（先左后右）进行下一步查找
        if(result==false){
            result=isSubStructure(A->left,B);
        }
        if(result==false){
            result=isSubStructure(A->right,B);
        }
        return result;
    }
};




/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    TreeNode* mirrorTree(TreeNode* root) {
        if(root==nullptr)
            return root;
        //设置出口
        if(root->left==nullptr&&root->right==nullptr){
            return root;
        }
        //开始翻转
        TreeNode *tem;
        tem=root->left;
        root->left=root->right;
        root->right=tem;
        if(root->left!=nullptr){
            mirrorTree(root->left);
        }
        if(root->right!=nullptr){
            mirrorTree(root->right);
        }
        return root;
    }
};